//对于axios进行二次封装
import axios from "axios";
import store from "@/store";


//创建axios实例
const requests = axios.create({
    //配置对象
    baseURL:"/api",
    //请求超时时间
    timeout:10000
});

//请求拦截器
requests.interceptors.request.use((config)=>{
    if (store.state.user.token){
        config.headers['Authorization'] = `Bearer ${store.state.user.token}`
    }
    return config
    })

//响应拦截器
requests.interceptors.response.use((res)=>{
    return res.data.data;
},(error)=>{
    return Promise.reject(error.response);
})
export default requests
